package com.xcity.game.employee.template;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.game.employee.Clazz;
import com.xcity.game.employee.EmployeeQuality;
import com.xcity.game.skill.template.SkillTemplate;

import naga.x.App;
import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.TemplateService;
import naga.x.game.template.annotation.Binding;
import naga.x.game.template.annotation.Excel;

/**
 * 员工列表
 * @author yang.li
 *
 */
@Excel(value = "employee.xlsx", sheetName = "员工列表")
public class EmployeeTemplate extends Template {

	public static final int V1 = 0;
	public static final int V2 = 20161229;
	
	protected int version;
	
	/** 品质 */
	protected EmployeeQuality quality;
	
	/** 姓名 */
	protected String name;
	
	/** 性别 */
	protected byte sex;
	
	/** 头像 */
	protected String icon;

	/** 精力 */
	@Deprecated
	protected int energy;

	/** 合成所需碎片id */
	protected int pieceId;

	/** 合成所需碎片数量 */
	protected int pieceCount;
	
	/** 解雇获得技能书概率（万分比） */
	@Deprecated
//	@JSONField(serialize = false)
	protected int skillBookOdds;
	
	/** 解雇赔偿金（支付后必得技能书） */
	@Deprecated
//	@JSONField(serialize = false)
	protected int compensation;
	
	/** 主动技能 */
//	@JSONField(serialize = false)
	protected int activeSkillId;
	protected SkillTemplate activeSkillTemplate;
	
	//---v2---
//	@JSONField(serialize = false)
	protected Clazz clazz;
	
	/** 力量 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float STR;
	
	/** 力量成长 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float STR_DELTA;
	
	/** 智力 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float INT;
	
	/** 智力成长 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float INT_DELTA;
	
	/** 敏捷 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float AGI;

	/** 敏捷成长 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float AGI_DELTA;
	
	/** 精神 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float SPI;
	
	/** 精神成长 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float SPI_DELTA;
	
	/** 耐力 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float STA;
	
	/** 耐力成长 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float STA_DELTA;
	
	/** 物攻系数 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float attackPowerRatio;
	
	/** 法攻系数 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float magicPowerRatio;
	
	/** hp系数 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float hpRatio;
	
	/** 出手速度系数 */
//	@JSONField(serialize = false)
	@Deprecated
	protected float attackSpeedRatio;
	
	/** 对应升品表id */
//	@JSONField(serialize = false)
	protected int upQualityId;
	
	/** 被动技能id */
	protected int[] passiveSkillIds;
	protected List<SkillTemplate> passiveSkillTemplates;
	
	/** 被动技能解锁星级 */
	protected int[] passiveSkillUnlockStarLvls;
	
	/** 羁绊 */
	protected List<EmployeeComboTemplate> combos;
	
	/**
	 * 开光对应表id [衣服, 手包, 手表, 鞋子]
	 */
	protected int[] blessId;
	
	public EmployeeQuality getQuality() {
		return quality;
	}

	public void setQuality(EmployeeQuality quality) {
		this.quality = quality;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public byte getSex() {
		return sex;
	}

	public void setSex(byte sex) {
		this.sex = sex;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@Deprecated
	public int getEnergy() {
		return energy;
	}

	@Deprecated
	public void setEnergy(int energy) {
		this.energy = energy;
	}

	public int getPieceId() {
		return pieceId;
	}

	public void setPieceId(int pieceId) {
		this.pieceId = pieceId;
	}

	public int getPieceCount() {
		return pieceCount;
	}

	public void setPieceCount(int pieceCount) {
		this.pieceCount = pieceCount;
	}

	@Deprecated
	public int getSkillBookOdds() {
		return skillBookOdds;
	}

	@Deprecated
	public void setSkillBookOdds(int skillBookOdds) {
		this.skillBookOdds = skillBookOdds;
	}

	@Deprecated
	public int getCompensation() {
		return compensation;
	}

	@Deprecated
	public void setCompensation(int compensation) {
		this.compensation = compensation;
	}

	public int getActiveSkillId() {
		return activeSkillId;
	}

	public void setActiveSkillId(int activeSkillId) {
		this.activeSkillId = activeSkillId;
	}
	
	public SkillTemplate getActiveSkillTemplate() {
		return activeSkillTemplate != null || activeSkillId == 0 ? activeSkillTemplate : (activeSkillTemplate = App.getApp().getServiceManager().get(TemplateService.class).get(SkillTemplate.class, activeSkillId));
	}
	
	public Clazz getClazz() {
		return clazz;
	}

	public void setClazz(Clazz clazz) {
		this.clazz = clazz;
	}

	@Deprecated
	public float getSTR() {
		return STR;
	}

	@Deprecated
	public void setSTR(float STR) {
		this.STR = STR;
	}

	@Deprecated
	public float getSTR_DELTA() {
		return STR_DELTA;
	}

	@Deprecated
	public void setSTR_DELTA(float STR_DELTA) {
		this.STR_DELTA = STR_DELTA;
	}

	@Deprecated
	public float getINT() {
		return INT;
	}

	@Deprecated
	public void setINT(float INT) {
		this.INT = INT;
	}

	@Deprecated
	public float getINT_DELTA() {
		return INT_DELTA;
	}

	@Deprecated
	public void setINT_DELTA(float INT_DELTA) {
		this.INT_DELTA = INT_DELTA;
	}

	@Deprecated
	public float getAGI() {
		return AGI;
	}

	@Deprecated
	public void setAGI(float AGI) {
		this.AGI = AGI;
	}

	@Deprecated
	public float getAGI_DELTA() {
		return AGI_DELTA;
	}

	@Deprecated
	public void setAGI_DELTA(float AGI_DELTA) {
		this.AGI_DELTA = AGI_DELTA;
	}

	@Deprecated
	public float getSPI() {
		return SPI;
	}

	@Deprecated
	public void setSPI(float SPI) {
		this.SPI = SPI;
	}

	@Deprecated
	public float getSPI_DELTA() {
		return SPI_DELTA;
	}

	@Deprecated
	public void setSPI_DELTA(float SPI_DELTA) {
		this.SPI_DELTA = SPI_DELTA;
	}

	@Deprecated
	public float getSTA() {
		return STA;
	}

	@Deprecated
	public void setSTA(float STA) {
		this.STA = STA;
	}

	@Deprecated
	public float getSTA_DELTA() {
		return STA_DELTA;
	}

	@Deprecated
	public void setSTA_DELTA(float STA_DELTA) {
		this.STA_DELTA = STA_DELTA;
	}

	@Deprecated
	public float getAttackPowerRatio() {
		return attackPowerRatio;
	}

	@Deprecated
	public void setAttackPowerRatio(float attackPowerRatio) {
		this.attackPowerRatio = attackPowerRatio;
	}

	@Deprecated
	public float getMagicPowerRatio() {
		return magicPowerRatio;
	}

	@Deprecated
	public void setMagicPowerRatio(float magicPowerRatio) {
		this.magicPowerRatio = magicPowerRatio;
	}

	@Deprecated
	public float getHpRatio() {
		return hpRatio;
	}

	@Deprecated
	public void setHpRatio(float hpRatio) {
		this.hpRatio = hpRatio;
	}

	@Deprecated
	public float getAttackSpeedRatio() {
		return attackSpeedRatio;
	}

	@Deprecated
	public void setAttackSpeedRatio(float attackSpeedRatio) {
		this.attackSpeedRatio = attackSpeedRatio;
	}
	
	public int getUpQualityId() {
		return upQualityId;
	}

	public void setUpQualityId(int upQualityId) {
		this.upQualityId = upQualityId;
	}
	
	public int[] getPassiveSkillIds() {
		return passiveSkillIds;
	}

	public void setPassiveSkillIds(int[] passiveSkillIds) {
		this.passiveSkillIds = passiveSkillIds;
	}
	
	public int[] getBlessId() {
		return blessId;
	}

	public void setBlessId(int[] blessId) {
		this.blessId = blessId;
	}

	public List<SkillTemplate> getPassiveSkillTemplates() {
		if (passiveSkillTemplates == null) {
			int[] ids = passiveSkillIds;
			if (ids != null && ids.length > 0) {
				passiveSkillTemplates = new ArrayList<>(ids.length);
				TemplateService ts = App.getApp().getServiceManager().get(TemplateService.class);
				for (int id : ids) {
					passiveSkillTemplates.add(ts.get(SkillTemplate.class, id));
				}
			} else {
				passiveSkillTemplates = Collections.emptyList();
			}
		}
		return passiveSkillTemplates;
	}

	public int[] getPassiveSkillUnlockStarLvls() {
		return passiveSkillUnlockStarLvls;
	}

	public void setPassiveSkillUnlockStarLvls(int[] passiveSkillUnlockStarLvls) {
		this.passiveSkillUnlockStarLvls = passiveSkillUnlockStarLvls;
	}

	//	@JSONField(serialize = false)
	public boolean isObsolete() {
		return version != V2;
	}
	
	public List<EmployeeComboTemplate> getCombos() {
		return combos;
	}

	@Binding(type = EmployeeComboTemplate.class, field = "id", ref = "id")
	public void setCombos(List<EmployeeComboTemplate> combos) {
		this.combos = combos;
	}

	@Override
	public void validate() throws TemplateException {
		if (clazz == null || clazz == Clazz.UNKNOWN) {
			version = V1;
		} else {
			version = V2;
		}
	}
}
